var app = getApp();
Page({
  onLoad(e){
    if (e.from && e.from =="kanjia"){
      this.setData({ jiekou: "/wechat/index/getbargainshareimage" });
      let json = { id: e.id };//user_bargain_id
      this.getimg(json);
    }else{
      this.setData({ jiekou:"wechat/index/getwxacode"});
      let json = { "type": e.tab, group_id: w.group_id}
      this.getimg(json);
    } 
  },
  getimg(json){
    app.request(this.data.jiekou, "POST", json, 'getimgb', this)
  },
  getimgb(data){
    console.log(data)
    this.setData({src:data.data.src});
  },
  data: {
  },
  save(){
    wx.downloadFile({
      url: this.data.src,
      success(res){
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success(res){
            wx.showToast({
              title: '保存成功~',
              icon: 'success',
              duration: 2000
            })
          },
          fail() {
            wx.showToast({
              title: '保存失败',
              icon: 'none',
              duration: 2000
            })
          }
        })
      }
    })
  },
  fail(){
//    console.log('fail')
  }
});